package com.tourismhengyang.impl;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.tourismhengyang.beans.Hotel;
import com.tourismhengyang.biz.IHotelBiz;
import com.tourismhengyang.dao.DBAccess;

public class HotelBizImpl implements IHotelBiz{
	private DBAccess db=new DBAccess();
	
	@Override
	public List<Hotel> getHotelList() {
		SqlSession session = null;
		List<Hotel> result=null;
		try {
			session=db.getSqlSession();
			IHotelBiz hotelBiz=session.getMapper(IHotelBiz.class);
			result=hotelBiz.getHotelList();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	
	@Override
	public int addHotelInfo(Hotel ht) {
		SqlSession session = null;
		int result=0;
		try {
			session=db.getSqlSession();
			IHotelBiz hotelBiz=session.getMapper(IHotelBiz.class);
			result=hotelBiz.addHotelInfo(ht);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}

	@Override
	public int updateHotelInfo(Hotel ht) {
		SqlSession session = null;
		int result=0;
		try {
			session=db.getSqlSession();
			IHotelBiz hotelBiz=session.getMapper(IHotelBiz.class);
			result=hotelBiz.updateHotelInfo(ht);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}

	@Override
	public Hotel getOneHotelInfo(int hid) {
		SqlSession session = null;
		Hotel result=null;
		try {
			session=db.getSqlSession();
			IHotelBiz hotelBiz=session.getMapper(IHotelBiz.class);
			result=hotelBiz.getOneHotelInfo(hid);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}

	@Override
	public List<Hotel> getOneHotel(int lid) {
		SqlSession session = null;
		List<Hotel> result=null;
		try {
			session=db.getSqlSession();
			IHotelBiz hotelBiz=session.getMapper(IHotelBiz.class);
			result=hotelBiz.getOneHotel(lid);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
}
